package com.eascs.workflow.dictionary.dao.impl;

import java.util.List;
import org.springframework.stereotype.Repository;
import com.eascs.workflow.common.dao.BaseDao;
import com.eascs.workflow.common.entity.wf.DicData;
import com.eascs.workflow.dictionary.dao.DicDataDao;

@Repository
public class DicDataDaoImpl extends BaseDao implements DicDataDao {

	@Override
	public List<DicData> getDicDataByType(String dataType) {
		String sql = "select d.`code`,d.`name` from wf_dictionary_data d ,wf_dictionary_type t where t.id = d.type and t.type= ?";
		return workflowJdbcSession.findEntitys(sql, DicData.class, dataType);
	}

	@Override
	public List<DicData> getDicDataByTypeAndKeys(String dataType, List<String> keys) {
		String sql = "select d.`code`,d.`name` from wf_dictionary_data d ,wf_dictionary_type t where t.id = d.type and t.type= ?";
		StringBuffer keyBuf = new StringBuffer();
		for (String key : keys) {
			keyBuf.append("'").append(key).append("',");
		}
		if (keyBuf.length() > 0) {
			sql = sql + " and d.code in (" + keyBuf.substring(0, keyBuf.length() - 1) + ")";
		}
		return workflowJdbcSession.findEntitys(sql, DicData.class, dataType);
	}

}
